package com.ptszyxx.popose.module.main.mine;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;
import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.FragmentMineAccountBinding;
import com.ptszyxx.popose.module.main.mine.vm.MineAccountVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.utils.YDialogUtil;

public class MineAccountFragment extends BaseFragment<FragmentMineAccountBinding, MineAccountVM> {
    public static MineAccountFragment getInstance() {
        return new MineAccountFragment();
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_mine_account;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MineAccountVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(MineAccountVM.class);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.uc.onCancelEvent.observe(this, o -> showDialogCancel());
    }

    /**
     * 账户注销
     */
    private void showDialogCancel() {
        YDialogUtil.getInstance().showConfirm(getContext(), getResources().getString(R.string.dialog_account_content))
                .setOnConfirmListener(()-> viewModel.requestWriteOff());
    }
}
